from django.utils.deprecation import MiddlewareMixin
from web import models


class AuthMiddlewareMixin(MiddlewareMixin):
    '''
    如果用户登录，在request中赋值
    '''

    def process_request(self, request):
        user_id = request.session.get('user_id', 0)
        user_obj = models.UserIfo.objects.filter(id=user_id).first()
        request.tracer = user_obj
